### TYPE LEVEL VARIABLES

# A) Project Categories

# Number of projects:

l_t <- L - rowSums(types[,2:(L+1)] == 0)

# Replace category codes in residual types:

types[ types == -1 ] <- NA

# Table of project categories for each network type:

Xp_t <- types[,2:ncol(types)]
Xp_t[types[,2:ncol(types)] == 0] <- NA

###

# B) Predicted Impact of Each Project

# Predicted impact for each project category:

# cbind(tapply(Y, X_P, min), tapply(Y, X_P, mean) , tapply(Y, X_P, max) )
# (min, mean, max are the same)

temp1 <- tapply(Y, X_P, mean)

# Table of predicted impacts for each network type:

Y_t <- matrix(temp1[Xp_t], nrow=nrow(Xp_t), ncol=ncol(Xp_t) )

# Replace NA's for isolated types:

Y_t[types[,"X1"]==0, 1] <- 0

###

# B) Number of Authors

attach(articles)

# Number of authors for each project type:

# cbind(tapply(num_authors_trunc, X_P, min), tapply(num_authors_trunc, X_P, mean) , tapply(num_authors_trunc, X_P, max) )
# (min, mean, max are the same)

temp2 <- tapply(num_authors_trunc, X_P, mean)

# Table of number of authors for each network type:

N_t <- matrix(temp2[Xp_t], nrow=nrow(Xp_t), ncol=ncol(Xp_t) )

# Replace NA's for isolated types:

N_t[types[,"X1"]==0, 1] <- 0

###

# C) Skill Differences

# Indicators for skill differences and any generalists:

# cbind(tapply(skill_diff, X_P, min), tapply(skill_diff, X_P, mean) , tapply(skill_diff, X_P, max) )
# cbind(tapply(any_gen50, X_P, min), tapply(any_gen50, X_P, mean) , tapply(any_gen50, X_P, max) )
# (min, mean, max are the same)

temp3 <- tapply(skill_diff, X_P, mean) == 1
temp4 <- tapply(any_gen50, X_P, mean) == 1

# Tables of indicators for skill differences and any generalists:

skl_t <- matrix(temp3[Xp_t], nrow=nrow(Xp_t), ncol=ncol(Xp_t) )
gen_t <- matrix(temp4[Xp_t], nrow=nrow(Xp_t), ncol=ncol(Xp_t) )

# Replace NA's for isolated types:

skl_t[types[,"X1"]==0, 1] <- FALSE
gen_t[types[,"X1"]==0, 1] <- FALSE

detach(articles)

###

# D) Residual Types

if (any(is.na(types) ) )  {
	temp1 <- which(is.na(types[,2]) )
	temp1 <- temp1[(nrow(typesR1)+1):length(temp1)]
	temp2 <- sum(c(countsR2b, countsR2c, countsR2d) > 0)
	temp3 <- sum(c(countsR2e, countsR2f, countsR2g) > 0)
	  N_t[temp1[1:nrow(typesR2a)],1] <- 1
	  N_t[temp1[nrow(typesR2a) + (1:temp2)],1] <- 3
	  N_t[temp1[nrow(typesR2a) + temp2 + (1:temp3)],1] <- 4
	skl_t[temp1,1] <- TRUE
	skl_t[temp1[1:nrow(typesR2a)],1] <- FALSE
	skl_t[temp1[nrow(typesR2a)+temp2-nrow(typesR2d) + (1:sum(countsR2d > 0))],1] <- FALSE
	skl_t[temp1[nrow(typesR2a)+temp2+temp3-nrow(typesR2g) + (1:sum(countsR2g > 0))],1] <- FALSE
	gen_t[temp1,1] <- FALSE
	gen_t[temp1[nrow(typesR2a)+nrow(typesR2b)-2 + (1:sum(countsR2c > 0))],1] <- TRUE
	gen_t[temp1[nrow(typesR2a)+temp2+nrow(typesR2e)-2 + (1:sum(countsR2f > 0))],1] <- TRUE
	# Check first 111 rows:
	cbind(types,l_t,N_t,skl_t,gen_t,counts)[1:111,]
}
